package com.example.zyfypt_206shj.fragement;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zyfypt_206shj.R;
import com.example.zyfypt_206shj.adapter.ProjectAdapter;
import com.example.zyfypt_206shj.adapter.TwareAdapter;
import com.example.zyfypt_206shj.bean.ProjectBean;
import com.example.zyfypt_206shj.bean.SessionID;
import com.example.zyfypt_206shj.bean.TwareBean;
import com.example.zyfypt_206shj.bean.UserInfo;
import com.example.zyfypt_206shj.iface.ProjectListener;
import com.example.zyfypt_206shj.model.ProjectModel;
import com.example.zyfypt_206shj.model.TwareModel;

import java.util.List;


/**
 * Created by Neusoft on 2017/4/9.
 */

public class Fragment_project extends Fragment {
    private View view=null;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private ProjectAdapter projectAdapter;
    private List<ProjectBean> list=null;
    private ProjectListener projectListener = new ProjectListener() {
        @Override
        public void onResponse(List<ProjectBean> beanlist) {
            list = beanlist;
            projectAdapter.setList(list);
            projectAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "fail" + msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
       //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment_project,container,false);
        //获取布局上的控件，注意通过view获取
        //返回动态生成的view
        initRecyclerView();
        ProjectModel projectModel = new ProjectModel();
        projectModel.getResultList("project", 1, SessionID.sessionID, projectListener);
        return view;
    }
    private void initRecyclerView(){
        layoutManager = new LinearLayoutManager(getContext());

        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerView_project);
        //创建默认线性布局
        recyclerView.setLayoutManager(layoutManager);
        //固定每个item的高度，可以提高性能
        recyclerView.setHasFixedSize(true);
        //获取数据
        //list=getData();
        //实例化adapter
        projectAdapter=new ProjectAdapter(getContext());
        projectAdapter.setList(list);
        recyclerView.setAdapter(projectAdapter);
    }
}
